<!DOCTYPE html>
<html lang="zh">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>在线用户</title>

    <script charset="utf-8" type="text/javascript" src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
    <script charset="utf-8" type="text/javascript" src="/js/com.wxd.js"></script>
    <script charset="utf-8" type="text/javascript" src="/pageview.js"></script>

    <link rel="stylesheet" type="text/css" href="/style/com.wxd.css"/>
    <link rel="stylesheet" type="text/css" href="/style/table.css"/>

    <style>
        html, body {display: block;width: 100%;height: 100%;overflow: hidden;overflow-x: auto;background: rgb(255, 255, 255);}

        a:link {color: #0866b4;}

        a:visited { color: #0866b4;}

        label {padding-left: 5px;padding-right: 5px;}

    </style>

    <script>

        function parentLoading() {
            wxd.loading();
        }

        function parentLoading_close() {
            wxd.loading_close();
        }

        function parentNotice(content, isError, closeTime) {
            wxd.message.notice(content, isError, closeTime);
        }

        function parentAlert(msg, refresh) {
            wxd.message.alert(
                msg,
                "提示：",
                "关闭",
                () => {
                    setTimeout(() => {
                        $("#div_load_box").parent().remove();
                        if (refresh) search();
                    }, 1);
                }
            );
        }

        function parentRefresh() {
            setTimeout(() => {
                $("#div_load_box").parent().remove();
                search();
            }, 1);
        }

        let pageView;

        function operate(sid, opt) {
        }

        function search() {
            wxd.loading();
            let urlQuery = new wxd.Map().loadSearch();
            urlQuery.put("sid", $("#sid").val());
            urlQuery.put("mainSid", $("#mainSid").val());
            urlQuery.put("name", $("#name").val());
            urlQuery.put("showName", $("#showName").val());
            urlQuery.put("wlan", $("#wlan").val());
            urlQuery.put("lan", $("#lan").val());
            pageView.remoteGetData(urlQuery);
        }

        function createRow(index, row) {
            let tr = `
    <tr>
            <td style="width: 120px;">
                <a href="#" onclick="edit(${row.uid},'${row.name}', '${row.showName}','${row.openTime}');return false;" title="服务器名字修改">禁用</a>
                <a href="#" onclick="del(${row.uid});return false;" title="删掉服务器">删除</a>
                <a href="#" onclick="edit(${row.uid},'${row.name}', '${row.showName}','${row.openTime}');return false;" title="服务器名字修改">改名</a>
            </td>
            <td tips="true" style="width: 80px;">${row.uid}</td>
            <td tips="true" style="width: 80px;">${row.mainSid}</td>
            <td tips="true" style="width: 140px;">${row.name}</td>
            <td tips="true" style="width: 140px;">${row.showName}</td>
            <td tips="true" style="width: 130px;">${row.openTime}</td>
            <td tips="true" style="width: 130px;">${row.maintainTime}</td>
            <td tips="true" style="width: 80px;">${row.registerRoleCount}</td>
            <td tips="true" style="width: 80px;">${row.onlineRoleCount}</td>
            <td tips="true" style="width: 80px;">${row.activeRoleCount}</td>
            <td tips="true" style="width: 120px;">${row.rechargeCount}</td>
            <td tips="true" style="width: 120px;">${row.rechargeAmount}</td>
            <td tips="true" style="width: 120px;">${row.wlan}</td>
            <td tips="true" style="width: 120px;">${row.lan}</td>
            <td tips="true" style="width: 62px;">${row.port}</td>
            <td tips="true" style="width: 62px;">${row.webPort}</td>
            <td tips="true" style="width: 300px;">${row.other}</td>
    </tr>
`;
            return tr;
        }

        function edit(sid, name, showName, openTime) {
            wxd.loadHtml('/server-edit.html?' + gameId() + '&sid=' + sid + '&name=' + name + '&showName=' + showName + '&openTime=' + openTime, '400px', '200px');
        }

        function del(sid, name) {
            wxd.message.alert(
                "确定要删除服务器 " + name + "(" + sid + ")？", "提示",
                "确定", () => {
                    let urlQuery = new wxd.Map().loadSearch();
                    urlQuery.put("sid", sid);
                    wxd.netty.post("/server/del", urlQuery.toString(),
                        function (responseText) {
                            if (responseText.code !== 1) {
                                parentNotice(responseText.msg);
                            } else {
                                parentNotice("成功");
                                parentRefresh();
                            }
                        }
                    );
                },
                "取消"
            );

            wxd.loadHtml('/server-edit.html?' + gameId() + '&sid=' + sid, '400px', '200px');
        }

        function openEditPlugin() {
            wxd.loadHtml("/server-list-edit.html?" + gameId(), "85%", "85%");
        }

        function openAdd() {
            wxd.loadHtml("/server-add.html?" + gameId(), "85%", "85%");
        }

        function openJson() {
            window.open("/server/json?" + gameId());
        }

        function gameId() {
            let urlQuery = new wxd.Map().loadSearch();
            return urlQuery.toString();
        }

        $(() => {
            pageView = new PageView("/server/list", search, createRow);
            search();
        });

    </script>

</head>

<body>
<div class="btn_box" style="text-align: left;padding-left: 10px;">
    <button class="submit" type="button" onclick="search();">搜索</button>
    <button class="submit" type="button" onclick="openAdd();">新增</button>
    <button class="submit" type="button" onclick="openJson();">正式列表Json</button>
    <button class="submit" type="button" onclick="openEditPlugin();">脚本</button>
    <br>
    <input id="sid" type="text" value="" onkeydown="if (event.keyCode===13)search();" placeholder="区服id"/>
    <input id="mainSid" type="text" value="" onkeydown="if (event.keyCode===13)search();" placeholder="主服id"/>
    <input id="name" type="text" value="" onkeydown="if (event.keyCode===13)search();" placeholder="区服名字"/>
    <input id="showName" type="text" value="" onkeydown="if (event.keyCode===13)search();" placeholder="显示名字"/>
    <input id="wlan" type="text" value="" onkeydown="if (event.keyCode===13)search();" placeholder="外网ip"/>
    <input id="lan" type="text" value="" onkeydown="if (event.keyCode===13)search();" placeholder="内网ip"/>
</div>
<div class="tableDom" style="position: absolute;left: 10px;top: 80px;right: 15px;bottom: 35px;">
    <table>
        <thead>
        <tr>
            <th style="width: 120px;">操作</th>
            <th style="width: 80px;">区服ID</th>
            <th style="width: 80px;">主服ID</th>
            <th style="width: 140px;">名字</th>
            <th style="width: 140px;">显示名字</th>
            <th style="width: 130px;">开服时间</th>
            <th style="width: 130px;">维护时间</th>
            <th style="width: 80px;">角色数</th>
            <th style="width: 80px;">在线</th>
            <th style="width: 80px;">活跃</th>
            <th style="width: 120px;">充值订单</th>
            <th style="width: 120px;">充值金额</th>
            <th style="width: 120px;">外网IP</th>
            <th style="width: 120px;">内网IP</th>
            <th style="width: 62px;">端口</th>
            <th style="width: 62px;">WEB端口</th>
            <th style="width: 300px;">其它</th>
        </tr>
        </thead>
        <tbody>

        </tbody>
    </table>
</div>
</body>
</html>